package org.yx.service.sres.delete_group_info;

import org.yx.exception.BizException;
import org.yx.models.SResGrpDef;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 删除设备资源组
 * @author zxw
 * @since 2022/04/13
 **/
public class SresDeleteGroupInfoService extends BaseService {
	public SresDeleteGroupInfoOut deleteGroupInfo(SresDeleteGroupInfoIn in) throws Exception {
		if (StrUtil.isBlank(in.getGroupCode())) {
			throw new BizException("SYS-0004", "请求的参数${parameter}要求不能为空。", FieldMap.of("parameter", "groupCode"));
		}

		SResGrpDef group = selectOneLocked(SResGrpDef.class, in.getUserOrgCode(), in.getGroupCode());
		if (group == null || "D".equals(group.getGroupStatus())) {
			throw new BizException("BAS-0008", "数据不存在或已被删除。");
		}
		group.setGroupStatus("D");

		update(group, "groupStatus");

		SresDeleteGroupInfoOut out = new SresDeleteGroupInfoOut();

		return out;
	}
}